package com.yowasa.xiuxian.engine.battle.strategy.skill.noele;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.engine.battle.strategy.BaseSpellStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import com.yowasa.xiuxian.util.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name = "玄妙剑")
@Order(502)
@Component
public class XuanMiaoJian extends BaseSpellStrategy {
    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return null;
    }

    @Override
    public void action(UserBattleContent first, UserBattleContent second, BattleContent content) {
        int atk = first.getBattleInfo().getSpell() + first.getBattleInfo().getAtk();
        int def = second.getBattleInfo().getRes();
        if (RandomUtil.randomInt(1, 100) <= 20) {
            def = 0;
        }
        int dmg = battleHelper.calAtk(atk, def);
        int costMp = first.getBattleInfo().getMp() / 10;
        first.getBattleInfo().setCmp(first.getBattleInfo().getCmp() - costMp);
        battleHelper.autoAction(this, first, second, content, dmg, "玄妙剑");
        first.getCd().put("玄妙剑", 3);
    }

    @Override
    public void limit(UserBO user) {
        if (user.getUserAttr().getUnd() > 30) {
            throw new HandlerException("学习/使用玄妙剑悟性必须低于30");
        }
    }

    @Override
    public String limitDesc() {
        return "悟性低于30";
    }

    @Override
    public String desc() {
        return "cd2回合 蓝耗10%的MP造成（术法攻击+物理攻击）的物理伤害,20%的概率忽略对方防御";
    }

    @Override
    public boolean check(UserBattleContent user, BattleContent content) {
        Integer cd = user.getCd().get("玄妙剑");
        if (cd != null && cd > 0) {
            return false;
        }
        int costMp = user.getBattleInfo().getMp() / 10;

        if (user.getBattleInfo().getCmp() < costMp) {
            return false;
        }
        return true;
    }
}
